//
//  MessageCenterViewModel.m
//  carcareIOS
//
//  Created by 王然 on 16/9/6.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "MessageCenterViewModel.h"

#import "MessageCarListViewController.h"

#import "MessageListViewModel.h"
@interface MessageCenterViewModel()

@property (nonatomic , strong) MessageCenterManager * messageCenterMgr;

@end

@implementation MessageCenterViewModel

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        __weak __typeof(self) wself = self;
        self.messageCenterMgr = [MessageCenterManager sharedInstance];
        RACSignal * modelsValidSignal = RACObserve(self.messageCenterMgr, messageCenterModels);
        [modelsValidSignal subscribeNext:^(NSArray<MessageCenterModel *> *models) {
            [((MessageCenterViewController *)wself.viewController).tableView reloadData];
        }];
    }
    return self;
}
-(NSInteger)MessageCenterNums
{
    return self.messageCenterMgr.messageCenterModels.count;
}
-(MessageCenterModel *)messageCenterAtIndex:(NSInteger)index
{
    return ((MessageCenterModel *)self.messageCenterMgr.messageCenterModels[index]);
}
- (void)updateMessageCenterData
{
    [self.messageCenterMgr updateSuccess:nil fail:nil];
}
-(void)clickOnMessageCenterAtIndex:(NSInteger)index
{
    MessageListViewModel * listViewModel = [[MessageListViewModel alloc]initWithMessageCenterModel:[self messageCenterAtIndex:index]];
    if (index == 0) {
        MessageCarListViewController *vc = [[[MessageCarListViewController alloc] initWithViewModel:listViewModel] navSetupBackItemWithIdentification:BACK_ICON_TITLE];
        [((MessageCenterViewController *)self.viewController).navigationController pushViewController:vc animated:YES];
    }else
    {
        MessageListNormalViewController * listVC = [[[MessageListNormalViewController alloc] initWithViewModel:listViewModel] navSetupBackItemWithIdentification:BACK_ICON_TITLE];
        [((MessageCenterViewController *)self.viewController).navigationController pushViewController:listVC animated:YES];
        
    }

}

@end
